/*    angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);*/
app.controller('ResOverController',['$scope', '$uibModal', "drmsSkillFlexibilityService", 'resCRUDService', function ($scope, $uibModal, drmsSkillFlexibilityService, resCRUDService) {
	$scope.oneAtATime = false;
  drmsSkillFlexibilityService.getInformation().then(function(informationData){
	  //console.log(informationData);
	  $scope.groups=informationData;
  });

  $scope.resourceDel = function(resId) {
	  resCRUDService.resDelete(resId).then(function() {
		  drmsSkillFlexibilityService.getInformation().then(function(informationData){
			  //console.log(informationData);
			  $scope.groups=informationData;
		  });
	  });
  }
  
  $scope.resourceAdd = function(resId){
	  $uibModal.open({
		 animation: false,
		 templateUrl: './views/resAdd.html',
		 size: 'lg',
		 controller: ['$scope', '$uibModalInstance', 'resCRUDService', function($scope, $uibModalInstance, resCRUDService) {
			 $scope.res = {
						resourceId: 0,
						username: null,
						capability: null,
						designation: null,
						dateOfJoin: null,
						kinId: null,
						name: null,
						chineseName: null,
						primarySkill: null,
						status: '1'
					}
			 
			 $scope.save = function() {
				 var keys = Object.keys($scope.res);
				 var isNull = false;
				 
				 for(var i = 0; i < keys.length; i++) {
					 if($scope.res[keys[i]] == null) {
						 isNull = true;
					 }
				 }
				 
				 if(!isNull) {
					 resCRUDService.resInsert($scope.res).then(function() {
						 drmsSkillFlexibilityService.getInformation().then(function(informationData){
							  //console.log(informationData);
							  $scope.groups=informationData;
							  $uibModalInstance.close();
						  });
					 }, function() {
						 
					 }) 
				 }
			 }
			 
		 }],
		 resolve: {
			 
		 }
	  });  
  }
  
  $scope.resourceEdit = function(resId){
	  var uibModal = $uibModal.open({
		 animation: false,
		 templateUrl: './views/resAdd.html',
		 size: 'lg',
		 controller: ['$scope', '$uibModalInstance', 'resourceDetailService', 'resCRUDService', 'resourceId', function($scope, $uibModalInstance, resourceDetailService, resCRUDService, resourceId) {
			 console.log(resourceId);
			 resourceDetailService(Number.parseInt(resourceId)).then(function(result) {
				 $scope.res = result;
			 })
			 
			 $scope.save = function() {
				 resCRUDService.resUpdate($scope.res).then(function() {
					 $uibModalInstance.close();
				 }, function() {
					 
				 })
			 }
		 }],
		 resolve: {
			 resourceId: function() {
				 return resId;
			 }
		 }
	  });
	  
	  uibModal.result.then(function(value) {
		  drmsSkillFlexibilityService.getInformation().then(function(informationData){
			  console.log(informationData);
			  $scope.groups=informationData;
		  })
	  })
  }
  
}]);
